package com.best.oasis.settlement.util;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.best.oasis.settlement.common.vo.supplier.SupplierVO;

public class SupplierImport {
	public static SupplierVO getSupplier(Connection con, String supplierCode) throws SQLException{
		SupplierVO vo = null;
		StringBuffer sql = new StringBuffer("select id,code,name from st_supplier where code='" + supplierCode + "'");
		PreparedStatement ps = con.prepareStatement(sql.toString());
		ResultSet rs = ps.executeQuery();
		while(rs.next()){
			vo = new SupplierVO();
			vo.setId(rs.getLong(1));
			vo.setCode(rs.getString(2));
			vo.setName(rs.getString(3));
		}
		rs.close();
		ps.close();
		return vo;
	}
	
	public static void updateSupplierBalance(Connection con, Long supplierId, Double amount) throws Exception{
		StringBuffer sql = new StringBuffer("update st_supplier set remainAmount = remainAmount" + amount + " where id=" + supplierId);
		PreparedStatement ps = con.prepareStatement(sql.toString());
		if(ps.executeUpdate() != 1)
			throw new Exception("更新数据供应商余额出错。");
	}
}
